﻿using System.Windows.Controls;
using System;
using System.Collections.Generic;

using System.Text;

namespace Bixas.Tangibilis.Controls
{
    internal class TouchTabItemAdapter : TouchUIElementAdapter<TouchTabItem>
    {
        public TouchTabItemAdapter(TouchTabItem element)
            : base(element)
        { }

        public override void OnTouchCursorDown(System.Windows.RoutedEventArgs e)
        {
            TouchTabItem element = (TouchTabItem)this.TouchElement;
            if (((e.Source == this) || !element.IsSelected) && this.CrackSetFocus())
            {
                e.Handled = true;
            }

            base.OnTouchCursorDown(e);
        }

        private bool CrackSetFocus()
        {
            TouchTabItem element = (TouchTabItem)this.TouchElement;
            return Phydeaux.Utilities.Dynamic<TabItem>.Instance.Function<bool>.Explicit.CreateDelegate("SetFocus").Invoke(element);
        }
    }
}
